﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;
using System.Data;

namespace DAO
{
    public class CHITIETPHIEUMUONSACHDAO
    {

        public DataTable laychitietphieumuonsach(string maphieumuon)
        {
            DataTable data = new DataTable();
            SqlConnection conn = DATAPROVIDER.ConnectSQL();
            string sql = "SELECT * FROM CHI_TIET_PHIEU_MUON_SACH WHERE MaChiTietPhieuMuonSach = '" + maphieumuon + "'";
            SqlDataAdapter datap = new SqlDataAdapter(sql, conn);
            datap.Fill(data);
            conn.Dispose();
            datap.Dispose();
            return data;
        }

        public int lapchitietphieumuonsach(CHITIETPHIEUMUONSACHDTO ctpmsDTO)
        {
            SqlConnection conn = DATAPROVIDER.ConnectSQL();
            string sql = "INSERT INTO CHI_TIET_PHIEU_MUON_SACH VALUES(@MCTPM,@MS,@TS,@TT)";
            SqlCommand cmd = new SqlCommand(sql, conn);

            SqlParameter para = new SqlParameter("@MCTPM", System.Data.SqlDbType.Int);
            para.Value = ctpmsDTO.Machitietphieumuonsach;
            cmd.Parameters.Add(para);

            para = new SqlParameter("@MS", System.Data.SqlDbType.NChar, 10);
            para.Value = ctpmsDTO.Masach;
            cmd.Parameters.Add(para);

            para = new SqlParameter("@TS", System.Data.SqlDbType.NVarChar,50);
            para.Value = ctpmsDTO.Tensach;
            cmd.Parameters.Add(para);

            para = new SqlParameter("@TT", System.Data.SqlDbType.NChar, 10);
            para.Value = ctpmsDTO.Tinhtrang;
            cmd.Parameters.Add(para);

            int kq = cmd.ExecuteNonQuery();
            conn.Close();
            conn.Dispose();
            return kq;
        }
    }
}
